import { OPENEDACTIVITY, DISCOUNTACTIVITY, BRANDACTIVITY, ACTRANK, PROMOTION, RANKSTEP, MYTEAM, MOREGOODSOVER } from './mutations-types'
export default {
  // TODO: 活动开启接口变化 list 由两个列表组成
  [OPENEDACTIVITY] (state, list) {
    state.openedActivity = list
  },
  [BRANDACTIVITY] (state, list) {
    state.brandActivity = list
  },
  [DISCOUNTACTIVITY] (state, data) {
    state.discountActivity = data
    state.nowDiscount = data.nowDiscount
    state.discountList = data.list || []
  },
  [ACTRANK] (state, object) {
    state.activityRank = object
  },
  [RANKSTEP] (state, value) {
    state.rankStep = value
  },
  [MYTEAM] (state, value) {
    state.myteam = value
  },
  [PROMOTION] (state, object) {
    state.activityPromotionList = object
    // 处理promotiondata
    // 没有未开始的活动
    let activityList = {}
    if (object.voList && !object.voList.length) {
      state.activityPromotionList.step = 2
      return
    }
    activityList = object.voList[0] || {}
    // 样式
    let startTimeParm = activityList.startTime
    let endTimeParm = activityList.endTime
    const starTimeStamp = (new Date(startTimeParm.replace(/-/g, '/'))).getTime()
    const endTimeStamp = (new Date(endTimeParm.replace(/-/g, '/'))).getTime()
    let nowTime = (new Date()).getTime()
    // 送红包活动开始
    if (nowTime > starTimeStamp && nowTime <= endTimeStamp) {
      state.activityPromotionList.step = 1
      return
    }
    // 活动还未开始
    if (nowTime < starTimeStamp) {
      state.activityPromotionList.step = 0
    }
    // 活动结束
    if (nowTime > endTimeStamp) {
      state.activityPromotionList.step = 2
    }
  },
  [MOREGOODSOVER] (state, array) {
    state.getMoreGoodsOver = array
  }
}
